package com.hl.yyx.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 映射静态资源
 */
@Configuration
public class StaticSourceConfig implements WebMvcConfigurer {

    @Value("${file.save.path}")
    private String fileSavePath;

    @Value("${source.mapping}")
    private String sourceMapping;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        try {
            registry.addResourceHandler(sourceMapping + "/**")
                    .addResourceLocations("file:" + fileSavePath);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
